import {
    Column,
    CreateDateColumn,
    Entity,
    JoinTable,
    ManyToMany,
    PrimaryGeneratedColumn,
    UpdateDateColumn,
} from 'typeorm';

import { PermissionEntity } from './permission.entity';
import { UserEntity } from './user.entity';

@Entity({
    name: 'roles',
})
export class RoleEntity {
    @PrimaryGeneratedColumn()
    id: number;

    @Column({
        length: 20,
        comment: '角色名',
    })
    name: string;

    @ManyToMany(() => PermissionEntity)
    @JoinTable({
        name: 'role_permissions',
    })
    permissions: PermissionEntity[];

    @CreateDateColumn({ comment: '创建时间' })
    createTime: Date;

    @UpdateDateColumn({ comment: '更新时间' })
    updateTime: Date;
}
